// home.js
import { reqCategoryList, reqSwiperList, reqFloorList } from '@/api/home'
const state = {
  cateList: [],
  swiperList: [],
  floorList: []
}

const getters = {}
const mutations = {
  saveCateList(state, cateList) {
    state.cateList = cateList
  },
  saveSwiperList(state, swiperList) {
    state.swiperList = swiperList
  },
  saveFloorList(state, floorList) {
    state.floorList = floorList
  }
}
const actions = {
  async getCateList(context) {
    // 获取三级分类数据
    const res = await reqCategoryList()
    // console.log(res)
    if (res.code === 200) {
      context.commit('saveCateList', res.data)
    }
  },
  async getSwiperList(context) {
    // 获取轮播图数据
    const res = await reqSwiperList()
    if (res.code === 200) {
      context.commit('saveSwiperList', res.data)
    }
  },
  async getFloorList(context) {
    // 获取楼层数据
    const res = await reqFloorList()
    if (res.code === 200) {
      context.commit('saveFloorList', res.data)
    }
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
